package com.qf.sportsevent.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.qf.sportsevent.R;
import com.qf.sportsevent.databinding.ActivityMainBinding;
import com.qf.sportsevent.fragment.NewsFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, SlidingPaneLayout.PanelSlideListener {
    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        List<Fragment> fragmentList=new ArrayList<>();
        fragmentList.add(new NewsFragment());
        fragmentList.add(new Fragment());
        fragmentList.add(new Fragment());
        binding.setFragmentList(fragmentList);

        FragmentManager manager = getSupportFragmentManager();
        binding.setFragmentManager(manager);

        binding.mainHead.setOnClickListener(this);
        binding.mainSlidingPane.setPanelSlideListener(this);
    }

    @Override
    public void onClick(View view) {
        if(binding.mainSlidingPane.isOpen()){
            binding.mainSlidingPane.closePane();
        }else{
            binding.mainSlidingPane.openPane();
        }
    }

    @Override
    public void onPanelSlide(View panel, float slideOffset) {
        ViewCompat.setAlpha(panel,1-slideOffset/2);
    }

    @Override
    public void onPanelOpened(View panel) {}
    @Override
    public void onPanelClosed(View panel) {}
}
